//
//  RankListTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/18.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "RankListTableViewCell.h"
#import <UIImageView+WebCache.h>

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation RankListTableViewCell
- (void)dealloc
{
    [_titleLabel release];
    [_image release];
    [_oneSongLabel release];
    [_twoSongLabel release];
    [_threeSongLabel release];
    [_rankDetailModel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.image = [UIImageView new];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.oneSongLabel = [UILabel new];
    self.oneSongLabel.textColor = [UIColor grayColor];
    self.oneSongLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.oneSongLabel];
    [_oneSongLabel release];
    
    self.twoSongLabel = [UILabel new];
    self.twoSongLabel.textColor = [UIColor grayColor];
    self.twoSongLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.twoSongLabel];
    [_twoSongLabel release];
    
    self.threeSongLabel = [UILabel new];
    self.threeSongLabel.textColor = [UIColor grayColor];
    self.threeSongLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.threeSongLabel];
    [_threeSongLabel release];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.image.frame = CGRectMake(WIDTH_PRO(10), HEIGHT_PRO(10), (SCREEN_WIDTH - WIDTH_PRO(40)) / 3, (SCREEN_WIDTH - WIDTH_PRO(40)) / 3);
    self.titleLabel.frame = CGRectMake(self.image.frame.size.width + WIDTH_PRO(30), self.image.frame.origin.y, SCREEN_WIDTH - self.image.frame.size.width - WIDTH_PRO(30), HEIGHT_PRO(20));
    self.oneSongLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height+ HEIGHT_PRO(15), _titleLabel.frame.size.width, HEIGHT_PRO(20));
    self.twoSongLabel.frame =CGRectMake(_oneSongLabel.frame.origin.x, _oneSongLabel.frame.origin.y + _oneSongLabel.frame.size.height + HEIGHT_PRO(10), _oneSongLabel.frame.size.width, HEIGHT_PRO(20));
    self.threeSongLabel.frame = CGRectMake(_twoSongLabel.frame.origin.x, _twoSongLabel.frame.origin.y + _twoSongLabel.frame.size.height + HEIGHT_PRO(10), _twoSongLabel.frame.size.width, HEIGHT_PRO(20));
    
}

-(void)setRankDetailModel:(RankDetailModel *)rankDetailModel
{
    if (_rankDetailModel != rankDetailModel) {
        [_rankDetailModel release];
        _rankDetailModel = [rankDetailModel retain];
    }
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:[rankDetailModel.image objectForKey:@"pic"]] placeholderImage:[UIImage imageNamed:@"Read_zhanwei"]];
    self.titleLabel.text = rankDetailModel.title;
    self.oneSongLabel.text = [NSString stringWithFormat:@"1. %@-%@", [rankDetailModel.songs[0] objectForKey:@"name"], [rankDetailModel.songs[0] objectForKey:@"singerName"]];
    self.twoSongLabel.text = [NSString stringWithFormat:@"2. %@-%@", [rankDetailModel.songs[1] objectForKey:@"name"], [rankDetailModel.songs[1] objectForKey:@"singerName"]];
    self.threeSongLabel.text = [NSString stringWithFormat:@"3. %@-%@", [rankDetailModel.songs[2] objectForKey:@"name"], [rankDetailModel.songs[2] objectForKey:@"singerName"]];
    
    
    
}

+(RankListTableViewCell *)rankListTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentify = @"rankListCell";
    RankListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[RankListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
